import java.util.Scanner;

public class Demo1 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int f1 = 0;
        int f2 = 1;
        int n = scan.nextInt();

        int sum = 0;
        int min = 0;
        for(int i = 0;sum <= n ; i++) {
            min = sum;
            sum = f1 + f2;
            f1 = f2;
            f2 = sum;
        }

        System.out.println(Math.abs(min - n) < Math.abs(sum - n)?Math.abs(min - n):Math.abs(sum - n));
    }
}
